<?php
	///////////////////////////////////////////////////////////////////////////////////////////////////
	//	SUBMIT TIME
	//	WRITTEN BY: TRAVIS THORNTON
	//	12-07-2009
	//
	//	What this page does:
	//	1) Shows a confirmation for submitting time for approval
	//	2) Updates the db and displays a results page.
	//
	////////////////////////////////////////////////////////////////////////////////////////////////////
	
	require_once 'php_includes.php';

	//default display confirmation html
	$display = 0;

	//if action = finish, update the table and show results
	if($_POST['action'] == "finish")
	{
		$sql = 'UPDATE `' . $dbname . '`.`PayPeriod` SET `PeriodStatus` = \'1\' WHERE EmployeeID = \'' . $_POST['usertime'] . '\' AND PeriodStart = \''. $_POST['period'] .'\' AND `PeriodStatus` = \'0\'';
		sqlConnect();
		$sqlresult = sqlQuery($sql);
		sqlExit();
		
		$display = 1;
	} 

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Payroll and Timesheet Management Website</title>
    <link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>
<?php
	//display confirmation
	if($display == 0)
	{
		echo "<p>";
		echo "    Are you sure you want to submit this time?";
		echo "   <br />";
		echo "	<form action=\"submittime.php\" method=\"post\">";
		echo "		<input type=\"hidden\" name=\"action\" value=\"finish\"/>";
		echo "		<input type=\"submit\" value=\"Yes\" class=\"button\" />";
		echo "	</form>";
		echo "</p>";
	}
	else
	{//display result
		echo "<p>";
		echo "    Timesheet submitted.";
		echo "   <br />";
		echo "		<input type=\"submit\" value=\"Okay\" class=\"button\" onclick=\"javascript:window.opener.location.href='main.php'; window.close();\"/>";
		echo "</p>";
	}
?>
</body>
</html>
